package com.situ.mall.web.config;

import com.situ.mall.web.interceptor.JWTInterceptor;
import com.situ.mall.web.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author yangkx
 * @create 2024-04-23-20:35
 * 配置类
 */
@Configuration
public class MyWebMVCConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor; // 登录校验拦截器
    @Autowired
    private JWTInterceptor jwtInterceptor; // token校验拦截器

    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor) // new一个拦截器的对象
                .addPathPatterns("/**") // 需要拦住哪些地址
                .excludePathPatterns("/client/login", "/client/register", "/client/changePassword", "/client/worker/register", "/client/worker/indexWorkers", "/client/order/allOrders", "/u/**", "/images/**");//需要忽略哪些地址
    }

    // 添加资源处理器（上传文件）
    // 将请求路径映射到本地路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/u/**")//浏览器只要发这个请求，就去下面指定的地址里找
                .addResourceLocations("file:D:\\静态资源\\");//file:+电脑硬盘中的实际地址 上传文件的文件夹的目录
    }
}
